package com.g2.rpc.util;

import java.util.ServiceLoader;

/**
 * 描述:
 * ${DESCRIPTION}
 *
 * @author lingjiu.kong
 * @version 1.0
 * @date 2021-03-03 23:34
 */
public class SpiUtil {

    public static <T> T load(Class<T> clazz, String name) {
        ServiceLoader<T> load = ServiceLoader.load(clazz);
        for (T t : load) {
            if (t.getClass().getSimpleName().equals(name)) {
                return t;
            }
        }
        throw new RuntimeException("未知" + clazz);
    }

}
